<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目产品报价</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
	<div class="Wrapper">
           <div id="pageInTab" class="pageInTab">
           <div class="searchArea">
    <form id="searchBar">
   <div class="fieldset1 clearFix">
   <div class="clearFix"></div>
   
</div>
</form>
</div>
<div id="grid" class="sq-grid"></div>
<div class="btnsBox" style="text-align: center;">
  <span id="selectBtn" class="sq-button sq-button-round"></i>确定</span>
                                 
</div>
</div>
</div>

<script type="text/javascript">
 // var s =  $("#searchBtnDIV").hide();//隐藏查询
	var prjId='${prjId}';
	var prjPrdId='${prjPrdId}';
	var prdFlag='${prdFlag}';
	var detailFlag='${detailFlag}';
	var grid = null;
	var ywParam = '${ywParam}';
	var buOrgCd = '${buOrgCd}';
	$(function () {
		initGrid();//grid
		if(detailFlag=="true"){
			$("#removeBtn").hide();
			$("#addBtn").hide();
			$("#addGPSCardBtn").hide();
		}
	});
	
	//初始化列表
	function initGrid(){
		var manager = null;
		var params = {};
		if(prdFlag){
		params.prjPrdId = prjPrdId;
		}else{
		params.prjId = prjId;
		}
		manager =  $("#grid").ligerGrid({
	    	url: '<%=path%>/project/prjprddtl/initList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	            { display: '产品名称', name: 'prdNm', minWidth: 100,
	             	
	            	enabledSort:true},
	            { display: '车辆型号', name: 'prdMdl', minWidth: 140,enabledSort:true},
	            getPaySchNoColumn(),
	            { display: '挂靠公司名称', name: 'lnkCompNm', minWidth: 100 ,
	            	render: function (rowdata, rowindex, value, column) { 
	            		 value ==null?"":value;
	            		var h = '';
	            		if(value){
	            		if(rowdata.prjLnkCompVO){
	            		  if(rowdata.prjLnkCompVO.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.prjLnkCompVO.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
		                    	h+='<i class="ico_flasher"></i>';
		                    }
	            		}
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.lnkCompId+"'";
	                        h+=')">'+value+'</a>'
	                        
	            		}
	                        return h;
	                        
	            		},
	            	enabledSort:true},
	            	  { display: '合格证编号', name: 'certNo', 
	            		render: function (rowdata, rowindex, value, column) { 
		            		var h = '';
	            			if(value){
		            		    h+='<a  href="javascript:detailVehBtn(';
		                        h+="'"+rowdata.actPrdId+"',";
		                        h+="'"+rowdata.id+"'";
		                        h+=')">'+value+'</a>'
	            			}
		            		   
		                        return h;
		            		},
	            		minWidth: 180, enabledSort:true},
	            	  { display: 'GPS卡号1', name: 'gpsCardNo', minWidth: 160, editor: {type: 'text'}, enabledSort:true},
	            	  { display: 'GPS卡号2', name: 'gpsCardNo2', minWidth: 160,editor: {type:'text'}, enabledSort:true},
	            	  getVinColumn(),
	            	  
	            
	        ],
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        isSingleCheck: true,
	        allowUnSelectRow: true,
            alternatingRow: true,
	        rownumbers:true,
	       // enabledEdit: true,
	        usePagerOnLessPagesize: true,
	    });
		grid = liger.get("grid");
		grid.setHeight(100);
		
	}
	
	function getPaySchNoColumn(){
		var column;
		if(ywParam == 1){
			column ={ display: '支付表号', name: 'paySchNo', minWidth: 140,enabledSort:true,
					render: function (rowdata, rowindex, value){
						if(StringUtils.isEmpty(rowdata.paySchNo)){
							return "";
						}else{
							return rowdata.paySchNo;
						}
                	} 
			};
		}
		return column;
	}
	
	//获取逾期天数列
	function getVinColumn(){
		var column;
		if(detailFlag!="true"){
			column ={ display: 'VIN', name: 'vin', minWidth: 160, editor: {type: 'text'}, enabledSort:true,
          		  render: function (rowdata, rowindex, value){
                        return rowdata.vin;
                	}  
          	  };
			
		}else{
			column ={ display: 'VIN', name: 'vin', minWidth: 160,  enabledSort:true,
	          		  render: function (rowdata, rowindex, value){
	                		var h="";
	                		if(StringUtils.isNotEmpty(rowdata.vin)){
	                			h='<a class="sq-button-hasicon" href="javascript:toRePrjPageList(';
	                            h+="'vin','"+rowdata.vin+"'";
	                            h+=')"><i class="sqBtnIco_1"></i></a>';
	                            h+='&nbsp;&nbsp;&nbsp;&nbsp;'+rowdata.vin;
	                        }else{
	                        	h = rowdata.vin;
	                        }
	                        return h;
	                	}  
	          	  };
		}
		return column;
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
        var h="￥" + FormatMoney(value)
        return h;
    }

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value&&value!=''){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	///* 查询 */
        $("#searchBtn1").click(function (event) {
        	grid.reload();
        });

	//添加挂靠公司
	function addBtn(){
		var callback = function(){
			 grid.reload();
		}
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		var prjId = "";
		for ( var index in selectedRows) {
			prjId = selectedRows[index].prjId
			_ids.push(selectedRows[index].id);
		}
		var ids = JSON.stringify(_ids);
        $.ligerDialog.open({  title: '添加产品挂靠公司',height: 500,width: 850, url:'<%=path%>/project/prjprddtl/toChooseLnkCompPage.do?ids='+ids+'&&prjId='+prjId,callback:callback});
	}
	
	

	function detailBtn(lnkCmpId){
		if(null==lnkCmpId){
			lnkCmpId = "";
		}
        //$.ligerDialog.open({  title: '挂靠公司详情',height: 500,width: 850, url:'<%=path%>/project/prjlnkcomp/toDetailPage.do?id='+lnkCmpId});
        Add_navTab( 'tab_prj_prd_lnk_detail'+lnkCmpId,'挂靠公司详情','<%=path%>/project/prjlnkcomp/toDetailPage.do?id='+lnkCmpId);
	}
	function detailVehBtn(id,dtlId){
		var detailFlag = true;
		Add_navTab( 'tab_prj_prd_veh_info_detail'+id,'合格证详情','<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag='+detailFlag+'&&id='+id+'&&dtlId='+dtlId);
	}
	//有拆分后的产品明细，显示拆分后的产品明细，否则显示项目产品
	function prdDetailBtn(dtlId,prjPrdId){
		//查询产品明细数据
		$.ajax({
			type: 'get',
			dataType:'json',
			data:{id:dtlId},
			url: '<%=path%>/project/prjprddtl/getPrjPrdDtlPrdInfoById.do',
			success:function(msg){
				 if(msg.success == 1){
						var detailFlag = true;
						var prdTypCd = '';
						Add_navTab( 'tab_prj_prd_dtl_info'+dtlId,'车辆信息详情','<%=path%>/project/prjprddtl/toModifyPrjPrdDtlPrdInfoPage.do?detailFlag='+detailFlag+'&&dtlId='+dtlId+'&&prdTypCd='+prdTypCd);
				 }else{
						var editFlag = true;
						Add_navTab('tab_prj_prd_info_detail'+prjPrdId,'项目产品详细信息','<%=path%>/project/vehicle/toModifyPage.do?id='+prjPrdId+'&&prjId='+prjId+'&&detailFlag='+editFlag);
				 }
			}
		});
		
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//所选信息
	function removeBtn(){
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		}
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjprddtl/removePrdDtlLnkCompByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
		
	}
	//保存
	function addGPSCardBtn(){
		 var gridData = grid.getData();
		 for ( var i=0; i<gridData.length;i++) {
       	  var obj = gridData[i];
       	  var gps1 = obj.gpsCardNo;
       	  var gps2 = obj.gpsCardNo2;
       /* 	  if(gps1){
	       	if(gps1.length!=8&&gps1.length!=11){
	    		top.$.ligerDialog.SQalert({content: "GPS1卡号仅支持维护8位或者11位!",SQ_type: "error"});
	    	return false ;
	    	}
       	  }
       	  if(gps2){
	       	if(gps2.length!=8&&gps2.length!=11){
	    		top.$.ligerDialog.SQalert({content: "GPS2卡号仅支持维护8位或者11位!",SQ_type: "error"});
	    	return false ;
	    	}	
       	  } */
	 }
		    var data = {};
	        var url = '<%=path%>/project/prjprddtl/modifyGpsInfos.do';
	        data["prjPrdDtlInfoList"] = JSON.stringify(gridData);
	        var wait_dialog;
	        $.ajax({
	    		type: 'post',
	    		dataType:'json',
	    		data:data,
	    		url: url,
	    		beforeSend: function(){
	  	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	  	     },
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){
	    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	    				 grid.reload();
	    			 }else{
	    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
		 
	}
	//查询项目信息(查重)
	function toRePrjPageList(type,value){
		var _cstId = '${cstId}';
		var _cstTypCd = '${cstTypCd}';
		if(StringUtils.isEmpty(_cstTypCd)){
			_cstTypCd=1;
		}
		if( StringUtils.isEmpty(prjId) || StringUtils.isEmpty(_cstTypCd))return;
		Add_navTab('tab_re_prj'+'-'+type+_cstId,'查重页面','<%=path%>/project/prjbscinfo/toRePrjListPage.do?id='+_cstId+'&cstTypCd='+_cstTypCd+'&prjId='+prjId+'&type='+type+'&value='+value);
	}
	
	//
	$("#selectBtn").click(function(){
		var data = grid.getData();
		var fileSelect = grid.getSelectedRows();
		if(fileSelect.length == 0){
			top.$.ligerDialog.SQalert({content:"您没有勾选任何产品，请选择",SQ_type: "error"});
			return false;
		}
		var prjPrdDtlId = fileSelect[0].id
		checkData(prjPrdDtlId);
		
	})
	//校验是否已做保险分期
	function checkData(prjPrdDtlId){
		 $.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{
	    			prjPrdDtlId:prjPrdDtlId
	    		},
	    		async: false,
	    		url: "<%=path%>/inscare/insapplication/checkData.do",
	    		beforeSend: function(){
	  	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	  	     	},
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){
	    				checkVehon(prjPrdDtlId);
	    				return true;
	    			 }else{
	    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    				 return false;
	    			 }
	    		},
	    		error:function(){
	    			 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
    				 return false;
	    		}
	    	});
	}
	//校验是否有合格证信息
	function checkVehon(prjPrdDtlId){
		 $.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{
	    			prjPrdDtlId:prjPrdDtlId
	    		},
	    		async: false,
	    		url: "<%=path%>/inscare/insapplication/checkVehon.do",
	    		beforeSend: function(){
	  	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	  	     	},
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){
	    				 var callback = function () {
	    					// parent.grid.reload();
	    					 Remove_navTab();    
	    					
	    		         };
	    				Add_navTab("fqApplication"+prjPrdDtlId, "分期申请", '<%=path%>/inscare/insapplication/toTabAddPage.do?prjPrdDtlId='+prjPrdDtlId, callback);
    					parent.$.ligerDialog.close();
    		        	parent.$(".l-dialog,.l-window-mask").css("display", "none");
	    				return true;
	    			 }else{
	    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    				 return false;
	    			 }
	    		},
	    		error:function(){
	    			 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
    				 return false;
	    		}
	    	});
	}	       
</script>
</body>
</html>